package com.yingpai.fitness.adpter.food;

import android.app.Activity;
import android.support.annotation.LayoutRes;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yingpai.fitness.R;
import com.yingpai.fitness.dvp_2_0.main.activity.fitness.DietCollocationActivity;
import com.yingpai.fitness.entity.food.DieCollocationBean;
import com.yingpai.fitness.widget.ChildRecyclerView;
import com.yingpai.fitness.dvp_2_0.main.widget.CustomGridLayoutManage;

import java.util.Arrays;

/**
=================================================
*作者:国斌
*邮箱: remebermelula@aliyun.com
*时间: 2018/4/24
*类名:  DieCollocationParentRecyclerAdapter .java
*版本: V 1.0
*描述:饮食搭配 适配器
 * {@link DietCollocationActivity ,com.yingpai.fitness.entity.food.DieCollocationBean}
===============================================
*/


public class DieCollocationParentRecyclerAdapter  extends BaseQuickAdapter<DieCollocationBean.MapData.DetailListWithPageData.ListData,BaseViewHolder> {


    private  Activity activity;

    /**
     * 子列表
     */
    private ChildRecyclerView die_collocation_rv_list;

    /**
     * 子适配器
     */
    private   DieCollocationChildAdapter dieCollocationChildAdapter;

    public DieCollocationParentRecyclerAdapter(@LayoutRes int layoutResId, Activity activity) {
        super(layoutResId);
        this.activity = activity;


    }



    @Override
    protected void convert(BaseViewHolder helper, DieCollocationBean.MapData.DetailListWithPageData.ListData item) {
        ImageView die_collocation_cover_iv = helper.getView(R.id.die_collocation_cover_iv);//图片


        Glide.with(activity)
                .load(item.getPhotoUrl())
                .centerCrop()
                .into(die_collocation_cover_iv);

        helper.addOnClickListener(R.id.die_collocation_cover_iv);


        TextView die_collocation_name=helper.getView(R.id.die_collocation_name);//食物名称

        die_collocation_name.setText(item.getDietDetailName());


        TextView die_collocation_kca=helper.getView(R.id.die_collocation_kca);//食物所含kca

        die_collocation_kca.setText(item.getEnergy());


        die_collocation_rv_list=helper.getView(R.id.die_collocation_rv_list);//子列表
        die_collocation_rv_list.setLayoutManager(new CustomGridLayoutManage(activity.getApplicationContext(),4));



        dieCollocationChildAdapter=new DieCollocationChildAdapter(R.layout.die_collocation_child_list_item);
        die_collocation_rv_list.setAdapter(dieCollocationChildAdapter);

        dieCollocationChildAdapter.addData(Arrays.asList(item.getProperties().split(",")));
    }
}
